<template>
	<el-dialog title="帖子信息" :visible.sync="dialogFormVisible" :before-close="cleardata">
		<el-form :model="form">
			<el-form-item label="标题" :label-width="formLabelWidth">
				<el-input v-model="form.postName" autocomplete="off" style="width: 40%;"></el-input>
			</el-form-item>
			<el-form-item label="发帖人" :label-width="formLabelWidth">
				<el-input v-model="form.nickName" autocomplete="off" style="width: 40%;" :disabled="true"></el-input>
			</el-form-item>
			<el-form-item label="帖子内容" :label-width="formLabelWidth">
				<div ref="editor"></div>
				
			</el-form-item>
			<el-form-item label="审核状态" :label-width="formLabelWidth">
				<!-- <el-switch
				    v-model="form.status"
				    active-color="#13ce66"
				    inactive-color="#ff4949"
				    active-value="1"
				    inactive-value="0"
					active-text="通过"
					inactive-text="未通过"
					>
				  </el-switch> -->
				  <el-switch v-model="form.status"
				  	:active-value="1"
				  	:inactive-value="0"
					active-text="通过"
					inactive-text="未通过"
				  	>
				  </el-switch>
			</el-form-item>
		</el-form>
		<div slot="footer" class="dialog-footer">
			<el-button @click="cleardata">取 消</el-button>
			<el-button type="primary" @click="examinePost">确 定</el-button>
		</div>
	</el-dialog>
</template>

<script>
	import PostsApi from "@/api/posts.js"
	import Editor from "wangeditor"
	export default {
		components: {
		},
		data() {
			return {
				editor: null,
				dialogVisible: false,
				imgurl: "",
				dialogFormVisible: false,
				form: {
					postId: "",
					postName: "",
					nickName: "",
					postContent: "",
					status: "",
				},
				formLabelWidth: '120px'
			};
		},
		methods: {
			//创建富文本容器
			createE(){
				this.$nextTick(()=>{
					this.editor = new Editor(this.$refs.editor)
					this.editor.config.uploadImgServer = "api/file/editUpload/posts"
					this.editor.config.uploadFileName = "file"
					this.editor.config.uploadVideoServer = 'api/file/editVideoUpload/posts'
					this.editor.config.uploadVideoName = "file"
					this.editor.create()
					this.editor.txt.html(this.form.postContent)
				})
			},
			cleardata() {
				this.dialogFormVisible = false;
				this.editor.destroy();
			},
			async examinePost() {
				let content = this.editor.txt.html();
				const res = await PostsApi.examinePost("/znExchangePost/examinePost", {
					postId: this.form.postId,
					postName: this.form.postName,
					nickName: this.form.nickName,
					postContent: this.form.postContent = content,
					status: this.form.status,
				});
				if (res.code == 200) {
					this.cleardata();
					this.$message.success("成功");
					this.$parent.SearchPostsAll();
				}else{
					this.$message.warning("失败");
				}
			}
		},
	};
</script>

<style lang="scss" scoped>
	.avatar {
	  float: left;
	  width: 148px;
	  height: 148px;
	  border-radius: 3%;
	  margin-right: 10px;
	  }
</style>